package cn.hesion.nio;
/**
 * ClassName: NIOFileChannel01 <br/>
 * Description: <br/>
 * date: 2021/1/21 15:51<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @program: NettyLearn
 * @description:
 * @author: hesion
 * @create: 2021-01-21 15:51
 **/
public class NIOFileChannel01 {
    public static void main(String[] args) throws Exception {
        File file = new File("d://file.txt");
        FileInputStream fileInputStream = new FileInputStream(file);

        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());

        channel.read(byteBuffer);

        System.out.println(new String(byteBuffer.array()));
        fileInputStream.close();
    }
}
